const fs=require('fs')
const dbConfig=require('../config/Zxdbconfig')
module.exports={
    imgPost(req,resp){
        /*获取前端请求数据*/
        let {imgUrl}=req.body
        /*1接收到64码*/
        let base64Str=imgUrl.replace(/data:image\/png;base64,/,'').replace('/\s/g','+')
        /*2将64码转换成文件*/
        let dataBuffer=Buffer.from(base64Str,'base64')
        /*3.保存  得到保存路径*/
        let fileName=new Date().getTime()+'_photo.png'
        fs.writeFile(`./src/upload/${fileName}`,dataBuffer,function () {
            let url = `./src/upload/${fileName}`
            let sql="insert into t_img value(?) "
            let arr=[url]
            dbConfig.DB(sql,arr,function (err,data) {
               if (!err){
                   resp.send('保存成功')
               }
            })

        })
    }
}